/**
 * Copyright (C), 2012-2018, 联奕科技有限公司
 * FileName: ImageCodeGenerator
 * Author:   石贵武
 * Date:     2018\3\9 0009 15:27
 * Description: 实现
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhoudongxiu.security.core.vaildators.generator;

import com.zhoudongxiu.security.core.properties.SecurityProperties;
import com.zhoudongxiu.security.core.vaildators.code.ValidateCode;
import com.zhoudongxiu.security.core.vaildators.generator.ValidateCodeGenerator;
import lombok.Data;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 〈一句话功能简述〉<br>
 * 〈实现〉
 *
 * @author 石贵武
 * @create 2018\3\9 0009
 * @since 1.0.0
 */
@Data
@Component("smsCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {


    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode createCode(ServletWebRequest request) {
        String code = RandomStringUtils.random(securityProperties.getCode().getSms().getLength());
        return new ValidateCode(code, securityProperties.getCode().getSms().getExpireInt());
    }
}